<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 羡羡
  Date: 2021/11/7
  Time: 15:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>头像切换</title>
    <script src="/SSMLifePlan/js/jquery-1.10.2.js"></script>
    <script>
        function fils(){
            $("#finp").click();
        }

        function wj(ev){
            var sr=document.getElementById("tp");
            //获取文件对象
            let file = ev.files[0];
            //获取文件阅读器
            let reader = new FileReader();
            reader.readAsDataURL(file);
            reader.onload = function(){
                //给img的src设置图片url
                sr.setAttribute("src", this.result);
            }
        }

    </script>

</head>
<body>
<form action="file" method="post" enctype="multipart/form-data">
    <c:choose>
        <c:when test="${sessionScope.imglj==null}">
            <img src="https://sls-study-cloud-1301165591.cos.ap-guangzhou.myqcloud.com/1636273382031.jpg" id="tp" style="width:200px;height: 200px;border-radius:50%" onclick="fils()"/>
        </c:when>
        <c:otherwise>
            <img src="${sessionScope.imglj}" id="tp" style="width:200px;height: 200px;border-radius:50%" onclick="fils()"/>
        </c:otherwise>
    </c:choose>
    <input type="file" name="multipart" style="display:none;" id="finp" onchange="wj(this)"/>
    <button type="submit">上传</button>
</form>
</body>
</html>
